

*This file takes the year of graduation from the 1975 census and links the indiuvidual  to the 1950 census to figure out in which municipality the person lived in 1939. Then by the person's 1939 municipality AGGREGATES the number of degrees in that municipality by the graduation year. 


global municipality mun39

*Use the 1950 data to find the person's municipality in 1939
use "W:\Matti M\vl50.dta" , clear
destring JNRO50, gen(id)

*-- Cleaning the VL50 data
destring PIKA50, gen(age50)
drop PIKA50

label var age50 "Age in 1950"
destring age50, replace
gen byear=1950-age50

rename AKUNU39 mun39
label var mun39 "Municipality of residence, 1939"

drop if shnro==""


preserve
use "$temp\municipality_shares_bartik_1939.dta" , clear
keep mun39
gen year=.
bys mun39: gen first= _n==1
 expand 66 if first==1
 bys mun39: gen N= _n
replace year=N+1904
rename year saikavv
 tempfile panel
 save `panel'
restore
 

preserve 
use shnro ktutk vuosi saikavv  syntyv ika  using "D:\ready-made\FOLK_vl_7085\vl7085_1.dta" if vuosi==1975 , clear
gen degree=(ktutk!="9999")
gen ktutk1=substr(ktutk,1,1)
destring ktutk1, replace
replace ktutk1=0 if ktutk1==.
gen hdegree=(ktutk1>5&ktutk1<9)

*Drop if no data to graduation
drop if  saikavv=="9999"

*Drop if no degree code
drop if ktutk=="999999"
destring saikavv , replace


tempfile data70 
save `data70' 

restore
 

*FJoin the 1970 data with the 1950 information
count
joinby  shnro using `data70', unmatched(master)
count 
 
keep if hdegree==1


gen ind=1
collapse (sum) ind, by(saikavv $municipality)
 

** make balanced panel (with zeros)
joinby $municipality saikavv using `panel', unmatched(using)

replace ind=0 if ind==.
 
 
*Join with the war reparations shock to the 1939 municipality
joinby $municipality using "$temp\shiftshare.dta" 


egen muni_g=group($municipality)

drop _merge


gen ln_degrees=ln(ind+1)
 
gen group0=(saikavv>=1925&saikavv<=1929)
gen group1=(saikavv>=1930&saikavv<=1934)
gen group2=(saikavv>=1935&saikavv<=1939)
gen group3=(saikavv>=1940&saikavv<=1944)
gen group4=(saikavv>=1945&saikavv<=1949)
gen group5=(saikavv>=1950&saikavv<=1954)
gen group6=(saikavv>=1955&saikavv<=1959)
gen group7=(saikavv>=1960&saikavv<=1964)
gen group8=(saikavv>=1965&saikavv<=1970)


gen group=0 if group0==1
forval x=1/8 {
replace group=`x' if group`x'==1
}

global municontrols_year c.agrishare_1940#saikavv c.manushare_1940#saikavv  city#saikavv town#saikavv 


forval x=0/8 {
gen b_group`x'=bartik_standardized*group`x'
}

*Save municipal-level high degrees for controls
preserve
keep if saikavv>1925&saikavv<1939
collapse (sum) ind, by($municipality)
gen ln_degrees_25_38=ln(ind)
save "$temp\hdegrees_muni_25_38.dta", replace
restore


*Event-Study graph

 local treat "b_group0  b_group1 b_group2  b_group4 b_group5 b_group6 b_group7 b_group8"
 tempfile model1 
 parmby " reghdfe ln_degrees  `treat'  [aw=individual]  if saikavv>1924, a(laani50#saikavv muni_g saikavv  $municontrols_year) cl(muni_g) " , lab saving(`"`model1'"', replace) idn(1) ids(Unadjusted)

 preserve
 clear all
 set obs 1
 gen group=3
 gen estimate=0
 gen parm="b_group3"
 gen min95=0
 gen max95=0
 append using `model1'
 keep if regexm(parm,"^b_group*")
 gen group_str=substr(parm,-1,1)
 destring group_str, replace  
 sort group_str
 
tw (scatter estimate group_str, msize(medium) mcolor(dknavy)) (rspike min95 max95 group_str, lcolor(dknavy)), xsize(6) ysize(4) xtitle(Year,) title("Estimates on ln higher degrees") xlabel(0 "1925-1929" 1 "1930-1934" 2 "1935-1939" 3 "1940-1944" 4 "1945-1949" 5 "1950-1954" 6 "1955-1959" 7 "1960-1964" 8 "1965-1969", angle(vertical)) xline(3.8, lcolor(maroon)) xline(5.2, lcolor(maroon)) plotregion(lcolor(black)) graphregion(lcolor(black) fcolor(white) color(white))  legend(off)  ytitle("", margin(0 1 0 0)) saving(muni_degrees.gph, replace)  

graph save "$temp\graphs\muni_cohort_hdegrees_ES", replace
graph export "$temp\graphs\muni_cohort_hdegrees_ES.eps", replace
 
restore


*Table
 
gen ln_degrees2=ln(ind)
 
gen repa_post=bartik_standardized*(saikavv>1943)

 
*Baseline 
  
reghdfe ln_degrees repa_post  [aw=individual]  if saikavv>1924, a(laani50#saikavv muni_g saikavv  $municontrols_year) cl(muni_g)
estadd local outcome "ln(y+1)"
estadd local em ""
estadd local sample "1925-1970"
estimates store d0

reghdfe ln_degrees repa_post  [aw=individual]  if saikavv>1934, a(laani50#saikavv muni_g saikavv  $municontrols_year) cl(muni_g)
estadd local outcome "ln(y+1)"
estadd local em ""
estadd local sample "1935-1970"
estimates store d0_2


*Only extensive

gen dummy=(ind>0)

reghdfe dummy repa_post  [aw=individual]  if saikavv>1924, a(laani50#saikavv muni_g saikavv  $municontrols_year) cl(muni_g)
estadd local outcome "I(y\textgreater0)"
estadd local em ""
estadd local sample "1925-1970"
estimates store dextensive

reghdfe dummy repa_post  [aw=individual]  if saikavv>1934, a(laani50#saikavv muni_g saikavv  $municontrols_year) cl(muni_g)
estadd local outcome "I(y\textgreater0)"
estadd local em ""
estadd local sample "1935-1970"
estimates store dextensive_2

*In tens of degrees

gen ln_degrees_10=ln((ind/10)+1)
reghdfe ln_degrees_10 repa_post  [aw=individual]  if saikavv>1924, a(laani50#saikavv muni_g saikavv  $municontrols_year) cl(muni_g)
estadd local outcome "ln((y/10)+1)"
estadd local em ""
estadd local sample "1925-1970"
estimates store dtens


reghdfe ln_degrees_10 repa_post  [aw=individual]  if saikavv>1934, a(laani50#saikavv muni_g saikavv  $municontrols_year) cl(muni_g)
estadd local outcome "ln((y/10)+1)"
estadd local em ""
estadd local sample "1935-1970"
estimates store dtens_2

*Calibrated extensive margin

preserve 
*If y=0 m(y)=0 , if y>0 m(y)=ln(gegrees)  
replace ln_degrees2=-3 if ind==0
reghdfe ln_degrees2 repa_post  [aw=individual]  if saikavv>1924, a(laani50#saikavv muni_g saikavv  $municontrols_year) cl(muni_g) 
estadd local outcome "ln(y) if y\textgreater0, -x if y=0"
estadd local em "3"
estadd local sample "1925-1970"
estimates store d1

reghdfe ln_degrees2 repa_post  [aw=individual]  if saikavv>1934, a(laani50#saikavv muni_g saikavv  $municontrols_year) cl(muni_g) 
estadd local outcome "ln(y) if y\textgreater0, -x if y=0"
estadd local em "3"
estadd local sample "1935-1970"
estimates store d1_2
restore 

preserve 
*If y=0 m(y)=0 , if y>0 m(y)=ln(gegrees) 
replace ln_degrees2=-1 if ind==0
reghdfe ln_degrees2 repa_post  [aw=individual]  if saikavv>1924, a(laani50#saikavv muni_g saikavv  $municontrols_year) cl(muni_g) 
estadd local outcome "ln(y) if y\textgreater0, -x if y=0"
estadd local em "1"
estadd local sample "1925-1970"
estimates store d2

reghdfe ln_degrees2 repa_post  [aw=individual]  if saikavv>1934, a(laani50#saikavv muni_g saikavv  $municontrols_year) cl(muni_g) 
estadd local outcome "ln(y) if y\textgreater0, -x if y=0"
estadd local em "1"
estadd local sample "1935-1970"
estimates store d2_2
restore 

preserve 
*If y=0 m(y)=0 , if y>0 m(y)=ln(gegrees) 
replace ln_degrees2=-0.1 if ind==0
reghdfe ln_degrees2 repa_post  [aw=individual]  if saikavv>1924, a(laani50#saikavv muni_g saikavv  $municontrols_year) cl(muni_g) 
estadd local outcome "ln(y) if y\textgreater0, -x if y=0"
estadd local em "0.1"
estadd local sample "1925-1970"
estimates store d3

reghdfe ln_degrees2 repa_post  [aw=individual]  if saikavv>1934, a(laani50#saikavv muni_g saikavv  $municontrols_year) cl(muni_g) 
estadd local outcome "ln(y) if y\textgreater0, -x if y=0"
estadd local em "0.1"
estadd local sample "1935-1970"
estimates store d3_2
restore 

preserve 
*If y=0 m(y)=0 , if y>0 m(y)=ln(gegrees) 
replace ln_degrees2=-0 if ind==0
reghdfe ln_degrees2 repa_post  [aw=individual]  if saikavv>1924, a(laani50#saikavv muni_g saikavv  $municontrols_year) cl(muni_g) 
estadd local outcome "ln(y) if \textgreate>0, -x if y=0"
estadd local em "0"
estadd local sample "1925-1970"
estimates store d4

reghdfe ln_degrees2 repa_post  [aw=individual]  if saikavv>1934, a(laani50#saikavv muni_g saikavv  $municontrols_year) cl(muni_g) 
estadd local outcome "ln(y) if y\textgreater0, -x if y=0"
estadd local em "0"
estadd local sample "1935-1970"
estimates store d4_2
restore 

labe var repa_post "Reaparations share x Post"


esttab  d0 dtens d4 d3 d2 d1 dextensive ///
using "$temp\tables\TABLE_degrees_posta.tex", ///
mgroups( "ln Higher degrees" "I(Higher degrees)"   , pattern(1 0 0 0 0 0 1 ) prefix(\multicolumn{@span}{c}{) suffix(}) ///
span erepeat(\cmidrule(lr){@span}) ) ///
replace keep(repa_post) nonotes ///s
b(%9.3f) se(%9.3f)  stats(N sample outcome em , fmt(0 3) layout(@ @ @ @) ///
labels("N" "Years" "Outcome"  "Extensive margin (x)" )) label star(* .1 ** .05 *** .01) nodepvars nomtitle


esttab   d0_2  dtens_2  d4_2  d3_2  d2_2 d1_2  dextensive_2 ///
using "$temp\tables\TABLE_degrees_postb.tex", ///
mgroups( "ln Higher degrees" "I(Higher degrees)"   , pattern(1 0 0 0 0 0 1 ) prefix(\multicolumn{@span}{c}{) suffix(}) ///
span erepeat(\cmidrule(lr){@span}) ) ///
replace keep(repa_post) nonotes ///s
b(%9.3f) se(%9.3f)  stats(N sample outcome em , fmt(0 3) layout(@ @ @ @) ///
labels("N" "Years" "Outcome"  "Extensive margin (x)" )) label star(* .1 ** .05 *** .01) nodepvars nomtitle



 